package com.ljyh.cygnus.utils

import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import com.ljyh.cygnus.serve.DevicePolicyService

object PolicyManager {
    private const val PREFS_NAME = "app_policy"
    // --- Keys ---
    private const val KEY_WIFI_POLICY = "wifi_policy"
    private const val KEY_MOBILE_DATA_POLICY = "mobile_data_policy"
    private const val KEY_HOTSPOT_POLICY = "hotspot_policy"

    // --- Policy Values ---
    const val POLICY_ENABLED = "ENABLED"
    const val POLICY_DISABLED = "DISABLED"
    const val POLICY_RESTRICTED = "RESTRICTED" // For Wi-Fi

    private fun getPrefs(context: Context): SharedPreferences {
        return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
    }


    fun setWifiPolicy(context: Context, policy: String) {

        getPrefs(context).edit().putString(KEY_WIFI_POLICY, policy).apply()
    }
    fun getWifiPolicy(context: Context): String {
        return getPrefs(context).getString(KEY_WIFI_POLICY, POLICY_ENABLED) ?: POLICY_ENABLED
    }

    // --- Mobile Data Policy ---
    fun setMobileDataPolicy(context: Context, policy: String) {
        getPrefs(context).edit().putString(KEY_MOBILE_DATA_POLICY, policy).apply()
    }
    fun getMobileDataPolicy(context: Context): String {
        return getPrefs(context).getString(KEY_MOBILE_DATA_POLICY, POLICY_ENABLED) ?: POLICY_ENABLED
    }

    // --- Hotspot Policy ---
    fun setHotspotPolicy(context: Context, policy: String) {
        getPrefs(context).edit().putString(KEY_HOTSPOT_POLICY, policy).apply()
    }
    fun getHotspotPolicy(context: Context): String {
        return getPrefs(context).getString(KEY_HOTSPOT_POLICY, POLICY_ENABLED) ?: POLICY_ENABLED
    }


}